﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FangPage.Core;
using FangPage.Common;

namespace FangPage.Boxing.Controller
{
    public class boxing:FPController
    {
        public override void Controller()
        {
            List<FPObject> list = GetData();

            Boxing _boxing = new Boxing();

            byte[] bytes = _boxing.DrawBoxing(1700, 800, list);

            //输入出图片
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            FPContext.HttpContext.Response.ContentType = "image/PNG";
            FPContext.HttpContext.Response.Body.WriteAsync(bytes);
        }

        /// <summary>
        /// 获取测试数据
        /// </summary>
        /// <returns></returns>
        public List<FPObject> GetData()
        {
            List<FPObject> list = new List<FPObject>();

            string filepath = FPPath.GetMapPath("/datas.log");

            string[] content = FPArray.SplitString(FPFile.Read(filepath), "|", 3);

            string[] picx = FPArray.SplitString(content[0]);

            string[] stressdata = FPArray.SplitString(content[1]);

            string[] temprdata = FPArray.SplitString(content[2]);

            for (int i = 0; i < picx.Length; i++)
            {
                FPObject obj = new FPObject();
                obj["picx"] = picx[i];
                obj["stressdata"] = stressdata[i];
                obj["temprdata"] = temprdata[i];

                list.Add(obj);
            }

            return list;
        }
    }
}
